<?php

/**
 * Part of the Fuel framework.
 *
 * @package    Fuel
 * @version    1.0
 * @author     Fuel Development Team
 * @license    MIT License
 * @copyright  2010 - 2012 Fuel Development Team
 * @link       http://fuelphp.com
 */

/**
 * Template Controller class
 *
 * A base controller for easily creating templated output.
 *
 * @package Fuel
 * @category Core
 * @author tien.tran@sgame.vn
 */

use Fuel\Core\Debug;

abstract class Controller_Rest extends Fuel\Core\Controller_Rest
{

    protected static $error_code = array(
            '1' => 'Success',
            '-1' => 'Not Success',
            '-401' => 'User not loggedin'
    );

    protected static $json = array(
            '_code' => - 1,
            '_message' => '',
            '_data' => ''
    );

    public static function setJson ($code = -1, $result = '', $message = '')
    {
        self::$json['_code'] = $code;
        self::$json['_message'] = ! empty($message) ? $message : self::$error_code[self::$json['_code']];
        self::$json['_data'] = $result;
        
        return self::$json;
    }

    public function before ()
    {
        $this->format = is_null(Input::extension()) ? 'json' : Input::extension();
        
        parent::before();
    }

}